package com.flkin.security;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 403 请求被限制
 *
 * @author yanxiang.huang
 */
@Component
public class IAccessDeniedHandler implements AccessDeniedHandler {

    private final static String FORBIDDEN = "Forbidden";

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException {
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e == null ? FORBIDDEN : e.getMessage());
    }

}
